package com.spring.shops.admin.controller.shop;

import com.spring.shops.model.result.IPageIndexImg;
import com.spring.shops.model.vo.IndexImg;
import com.spring.shops.model.dto.IndexImgDTO;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.service.IndexImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/indexImg")
public class IndexImageController {
    @Autowired
    private IndexImageService indexImageService;
    /**
     * 分页查询
     * @param
     * @return
     */
    @GetMapping("/page")
    public ServerResponseEntityVoid<IPageIndexImg<IndexImg>> page(
           IndexImgDTO indexImgDTO
           ){
        return indexImageService.page(indexImgDTO);
    }

    /**
     * 根据id查询信息
     * @param imgId
     * @return
     */
    @GetMapping("/info/{imgId}")
    public ServerResponseEntityVoid<IndexImg> getInfoById(@PathVariable Integer imgId){
        IndexImg indexImg=indexImageService.getById(imgId);
       return ServerResponseEntityVoid.success(indexImg);
    }

    /**
     * 批量删除数据
     * @param integers
     * @return
     */
    @DeleteMapping
    public ServerResponseEntityVoid deleteByIds(@RequestBody List<Integer> integers){
        boolean flag=indexImageService.deleteByIds(integers);
        if(flag){
            return ServerResponseEntityVoid.success();
        }else{
            return null;
        }
    }

    /**
     * 新增数据
     * @param indexImg
     * @return
     */
    @PostMapping
    public ServerResponseEntityVoid save(@RequestBody IndexImg indexImg){
        boolean flag=indexImageService.save(indexImg);
        if(flag){
            return ServerResponseEntityVoid.success();
        }else{
            return null;
        }
    }

    /**
     * 更新数据
     * @param indexImg
     * @return
     */
    @PutMapping
    public ServerResponseEntityVoid update(@RequestBody IndexImg indexImg){
        boolean flag=indexImageService.update(indexImg);
        if(flag){
            return ServerResponseEntityVoid.success();
        }else{
            return null;
        }
    }


}
